use SAS
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'DelRelationships')
	BEGIN
		DROP  Procedure  dbo.DelRelationships
	END
GO

CREATE Procedure [dbo].[DelRelationships] (
	@SOURCEGUID			VARCHAR(100)
,	@RELATIONSHIPTYPE	VARCHAR(10)
,	@PARTNERID			VARCHAR(10) = '0'
)
AS
BEGIN

	DELETE FROM TR_RELATIONSHIPS
	WHERE
		SOURCEGUID = @SOURCEGUID
	AND	RELATIONSHIPTYPE = @RELATIONSHIPTYPE
	AND	PARTNER2 =  CASE ISNULL(@PARTNERID, PARTNER2) 
						WHEN 0 THEN PARTNER2
						ELSE @PARTNERID
					END
END
GO
